/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lamhnhServlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author user
 */
@WebServlet(name="ActivityManage", urlPatterns={"/ActivityManage"})
public class ActivityManage extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try
        {
        String user =request.getParameter("txtuser");
        String pay = request.getParameter("txtpay");
        boolean sub = Boolean.parseBoolean(request.getParameter("txtsub"));
        String win = request.getParameter("txtwin");
        int act = Integer.parseInt(request.getParameter("txtact"));
        RequestDispatcher r1 = request.getRequestDispatcher("lamServletHeader.jsp");
        RequestDispatcher r2 = request.getRequestDispatcher("admin/adminFooter.jsp");
        String s1="";
        String s2="";
        String s3="";
        String s4="";
        String s5="";
        if(pay.equals("Cheque"))
        {
            s1="selected";
        }else
        {
            if(pay.equals("Demand Draft"))
            {
                 s2="selected";
            }else
            {
                s3="selected";
            }
        }
        if(sub==true)
        {
            s4 = "selected";
        }else
        {
            s5 = "selected";
        }
        out.println("<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><link rel='stylesheet' type='text/css' href='css/clientTemplate.css'><title>Member List</title></head><body><center><table id='tableClientTemplate'><tr id='headerClientTemplate' style='background-color: orange'><td>");
        r1.include(request, response);
        out.println("</td></tr><tr id='middleClientTemplate'><td>");
        out.print("<table align='center'>");
        out.print("<form action='updateActivityServlet' method='POST'>");
        out.print("<tr>");
        out.print("<td>");
        out.print("User Name:");
        out.print("</td>");
        out.print("<td>");
        out.print("<input type='text' name='txtuser' readonly value='"+user+"' />");
        out.print("</td>");
        out.print("</tr>");
        out.print("<tr>");
        out.print("<td>");
        out.print("Payment:");
        out.print("</td>");
        out.print("<td>");
        out.print("<select name='dr'><option "+s1+">Cheque</option><option "+s2+">Demand Draft</option><option "+s3+">Cash</option></select>");
        out.print("</td>");
        out.print("</tr>");
        out.print("<tr>");
        out.print("<td>");
        out.print("Submitted:");
        out.print("</td>");
        out.print("<td>");
        out.print("<select name='check'>");
        out.print("<option "+s4+">True</option>");
        out.print("<option "+s5+">False</option>");
        out.print("</select>");
        out.print("</td>");
        out.print("</tr>");
        out.print("<tr>");
        out.print("<td>");
        out.print("Wined:");
        out.print("</td>");
        out.print("<td>");
        out.print("<textarea name='area' rows='4' cols='20'>"+win+"</textarea>");
        out.print("</td>");
        out.print("</tr>");
        out.print("<tr>");
        out.print("<td>");
        out.print("<input type='hidden' name='txtact' readonly value='"+act+"' />");
        out.print("</td>");
        out.print("</tr>");
        out.print("<tr>");
        out.print("<td>");
        out.print("<input type='submit' value='Submit' />");
        out.print("</td>");
        out.print("<td>");
        out.print("<a href='ShowMemberActivity?txtact="+act+"'>Cancel</a>");
        out.print("</td>");
        out.print("</tr>");
        out.print("</form>");
        out.println("</table>");
        out.println("</td></tr><tr id='footerClientTemplate'><td>");
        r2.include(request, response);
        out.println("</td></tr></table></center></body></html>");
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
